import { ExAttributeItemLabel } from "./ExAttributeItemLabel";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { Language } from "../../../../../extend/language/Language";
import { DataEvent } from "../../../events/DataEvent";
import { EquipmentItemDataUtil } from "../../common/EquipmentItemDataUtil";
import { ItemData } from "../../../resource/info/ItemData";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class ExAttributePanel
    
    export  class ExAttributePanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._labelsVec = new Vector.<ExAttributeItemLabel>();
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=0;
            var loc2=null;
            this._bg = ObjCreate.createBg(0, 0, 140, 150, this);
            this._typeBitmapCur = new GImageBitmap("EquipRecast_current.png");
            this.addChild(this._typeBitmapCur);
            this._typeBitmapNew = new GImageBitmap("EquipRecast_new.png");
            this.addChild(this._typeBitmapNew);
            this._tip = ObjCreate.createLabel(Language.getString(60287), 0, 4, 140, 20, flash.text.TextFormatAlign.CENTER, this, true, 16702014);
            this._labelsVec.push(this._label1);
            this._labelsVec.push(this._label2);
            this._labelsVec.push(this._label3);
            this._labelsVec.push(this._label4);
            this._labelsVec.push(this._label5);
            this._labelsVec.push(this._label6);
            loc1 = 0;
            while (loc1 < this._labelsVec.length) 
            {
                loc2 = new ExAttributeItemLabel();
                loc2.addEventListener(loc2.LockClick, this.onLockStatusChange);
                this.addChild(loc2);
                this._labelsVec[loc1] = loc2;
                ++loc1;
            }
            this.sortLabels(true);
            return;
        }

        /* internal  */onLockStatusChange(arg1: Object /* flash.events.Event */): void
        {
            this.dispatchEvent(new DataEvent(ExAttributePanel.UseLockChange, this.lockPosDic, false, true));
            return;
        }

        public sortLabels(arg1: Boolean=false): void
        {
            var loc1=0;
            var loc2=null;
            if (arg1) 
            {
                loc1 = 0;
                while (loc1 < this._labelsVec.length) 
                {
                    this._labelsVec[loc1].x = 4;
                    this._labelsVec[loc1].y = 36 + loc1 * 18;
                    ++loc1;
                }
            }
            else 
            {
                loc2 = new Vector.<ExAttributeItemLabel>();
                loc1 = 0;
                while (loc1 < this._labelsVec.length) 
                {
                    if (this._labelsVec[loc1].useLock) 
                    {
                        loc2.push(this._labelsVec[loc1]);
                    }
                    ++loc1;
                }
                loc1 = 0;
                while (loc1 < this._labelsVec.length) 
                {
                    if (!this._labelsVec[loc1].useLock) 
                    {
                        loc2.push(this._labelsVec[loc1]);
                    }
                    ++loc1;
                }
                loc1 = 0;
                while (loc1 < loc2.length) 
                {
                    loc2[loc1].x = 4;
                    loc2[loc1].y = 36 + loc1 * 18;
                    ++loc1;
                }
            }
            return;
        }

        public get lockNum(): int
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < this._labelsVec.length) 
            {
                if (this._labelsVec[loc2].useLock) 
                {
                    loc1 = loc1 + 1;
                }
                ++loc2;
            }
            return loc1;
        }

        public get lockPosDic(): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=0;
            while (loc2 < this._labelsVec.length) 
            {
                if (this._labelsVec[loc2].useLock) 
                {
                    loc1[loc2 + 1] = loc2 + 1;
                }
                ++loc2;
            }
            return loc1;
        }

        public set lockPosDic(arg1: Map<any, any> /* flash.utils.Dictionary */)
        {
            var loc1=0;
            while (loc1 < this._labelsVec.length) 
            {
                if (arg1[loc1 + 1] == null) 
                {
                    this._labelsVec[loc1].useLock = false;
                }
                else 
                {
                    this._labelsVec[loc1].useLock = true;
                }
                ++loc1;
            }
            this.sortLabels();
            return;
        }

        public set type(arg1: string)
        {
            this._type = arg1;
            if (arg1 != ExAttributePanel.CurrentAttri) 
            {
                if (arg1 == ExAttributePanel.NewAttri) 
                {
                    this._typeBitmapCur.visible = false;
                    this._typeBitmapNew.visible = true;
                    this.changeLabelsStatus(false);
                }
            }
            else 
            {
                this._typeBitmapCur.visible = true;
                this._typeBitmapNew.visible = false;
                this.changeLabelsStatus(true);
            }
            return;
        }

        public set showBg(arg1: Boolean)
        {
            this._typeBitmapCur.visible = arg1;
            this._typeBitmapNew.visible = arg1;
            this._bg.visible = arg1;
            this._tip.visible = arg1;
            return;
        }

        public set showLock(arg1: Boolean)
        {
            var loc1=0;
            while (loc1 < this._labelsVec.length) 
            {
                this._labelsVec[loc1].showLock = arg1;
                ++loc1;
            }
            return;
        }

        /* internal  */changeLabelsStatus(arg1: Boolean): void
        {
            var loc1=0;
            while (loc1 < this._labelsVec.length) 
            {
                this._labelsVec[loc1].isCanChangeLock = arg1;
                ++loc1;
            }
            return;
        }

        public setAttributes(arg1: EquipmentItemDataUtil): void
        {
            var loc2=null;
            var loc3=NaN;
            var loc4=false;
            var loc6=0;
            this._currentEquipUtil = arg1;
            this.sortLabels(true);
            var loc1=[];
            if (arg1 && this._type == ExAttributePanel.CurrentAttri) 
            {
                loc1 = arg1.getAddtionalArray(false, true);
            }
            else if (arg1 && this._type == ExAttributePanel.NewAttri) 
            {
                loc1 = arg1.getNewAddtionalArray(false, true);
            }
            var loc5=0;
            while (loc5 < this._labelsVec.length) 
            {
                if (loc5 < loc1.length) 
                {
                    loc2 = loc1[loc5];
                    loc6 = 0;
                    if (loc2["star"]) 
                    {
                        loc6 = loc2["star"];
                    }
                    loc3 = (loc3 = arg1.getAddtionalReal(arg1.getBaseValueByAddition(loc2.addition), loc6) - 1);
                    if (this._type != ExAttributePanel.CurrentAttri) 
                    {
                        if (this._type == ExAttributePanel.NewAttri) 
                        {
                            loc4 = true;
                        }
                    }
                    else if (loc2["value"] >= loc3) 
                    {
                        loc4 = true;
                    }
                    else 
                    {
                        loc4 = false;
                    }
                    this._labelsVec[loc5].updateData(loc2["name"], this.getValueText(loc2["value"], loc6), loc2["lock"], loc5 + 1, loc4);
                }
                else 
                {
                    this._labelsVec[loc5].clear();
                }
                ++loc5;
            }
            this.sortLabels();
            return;
        }

        public setAttributesByAttrubutes(arg1: Array<any>, arg2: ItemData): void
        {
            var loc1=null;
            var loc3=null;
            var loc4=false;
            var loc5=NaN;
            var loc6=false;
            this.sortLabels(true);
            var loc2=arg2.itemExInfo.ref_lock.split(",");
            if (this._currentEquipUtil) 
            {
                this._currentEquipUtil.itemData = arg2;
            }
            else 
            {
                this._currentEquipUtil = new EquipmentItemDataUtil(arg2);
            }
            var loc7=0;
            while (loc7 < this._labelsVec.length) 
            {
                if (loc7 < arg1.length) 
                {
                    loc1 = arg1[loc7];
                    if (loc1[0] > 0) 
                    {
                        loc3 = GameDefConfig.instance.getEJewel(loc1[0]).text1;
                        loc4 = loc7 < (loc2.length - 1) ? true : false;
                        loc5 = (loc5 = this._currentEquipUtil.getAddtionalReal(this._currentEquipUtil.getBaseValueByAddition(loc1[0]), loc1[1]) - 1);
                        if (loc1[2] >= loc5) 
                        {
                            loc6 = true;
                        }
                        else 
                        {
                            loc6 = false;
                        }
                        this._labelsVec[loc7].updateData(loc3, this.getValueText(loc1[2], loc1[1]), loc4, loc7 + 1, loc6);
                    }
                    else 
                    {
                        this._labelsVec[loc7].clear();
                    }
                }
                else 
                {
                    this._labelsVec[loc7].clear();
                }
                ++loc7;
            }
            this.sortLabels();
            return;
        }

        /* internal  */getValueText(arg1: int, arg2: int): string
        {
            var loc1=arg1;
            var loc2=Language.getString(60288);
            if (loc1 < 10) 
            {
                return "+" + loc1 + "      （" + arg2 + loc2 + "）";
            }
            if (loc1 < 100) 
            {
                return "+" + loc1 + "    （" + arg2 + loc2 + "）";
            }
            if (loc1 < 1000) 
            {
                return "+" + loc1 + "  （" + arg2 + loc2 + "）";
            }
            return "+" + loc1 + "（" + arg2 + loc2 + "）";
        }

        public static /* const */UseLockChange: string="点击改变使用锁的状态";

        public static /* const */CurrentAttri: string="当前属性";

        public static /* const */NewAttri: string="最新属性";

        /* internal */ /* var */_currentEquipUtil: EquipmentItemDataUtil;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tip: GLabel;

        /* internal */ /* var */_typeBitmapCur: GImageBitmap;

        /* internal */ /* var */_typeBitmapNew: GImageBitmap;

        /* internal */ /* var */_labelsVec: Vector.<ExAttributeItemLabel>;

        /* internal */ /* var */_label1: ExAttributeItemLabel;

        /* internal */ /* var */_label2: ExAttributeItemLabel;

        /* internal */ /* var */_label3: ExAttributeItemLabel;

        /* internal */ /* var */_label4: ExAttributeItemLabel;

        /* internal */ /* var */_label5: ExAttributeItemLabel;

        /* internal */ /* var */_label6: ExAttributeItemLabel;

        /* internal */ /* var */_type: string;
    }
